using System.Windows.Forms;
using WindowsLive.Writer.Api;
using Bing;

namespace BingTranslatorPlugin
{
    [WriterPlugin("4012043a-ba0d-4da0-b0c2-2df45a6ef3e9", "Bing Translator Plugin",
        PublisherUrl = "http://scottisafooldev.spaces.live.com",
        Description = " ",
        ImagePath = "writer.png",
        HasEditableOptions = true)]
    [InsertableContentSource("Bing Translation")]

    public class BingTranslator : ContentSource
    {
        private const string appID = "73C88678682207F5DFB9E13D18BC3D5250D95638";

        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
        {
            using (frmMain form = new frmMain(appID))
            {
                DialogResult result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    // {0} = the tag. <p> or <blockquote>
                    // {1} = Where the title attribute will go
                    // {2} = Where the Translated text will go
                    string template = "<{0}{1}>{2}</{0}>";
                    string tag = form.UseQuotes ? "blockquote" : "p";
                    string title = form.UseOriginalAsTitle ? " title = \"" + form.OriginalText + "\"" : "";
                    content = string.Format(template, tag, title, form.TranslatedText);
                }
            }
            return DialogResult.OK;
        }
    }
}
